const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
  transpileDependencies: true,
  productionSourceMap: false,
  lintOnSave: true,
  publicPath: process.env.NODE_ENV === 'production' ? '/' : '/',
  devServer: {
    // client: {
    //   overlay: false,
    // },
  },
  chainWebpack: (config) => {
    config.optimization.minimizer('terser').tap((args) => {
      args[0].parallel = 4;
      const flag = process.env.NODE_ENV === 'production';
      console.log('【⭕ drop_console&debug】', flag);
      args[0].terserOptions.compress.warnings = flag;
      args[0].terserOptions.compress.drop_debugger = flag;
      args[0].terserOptions.compress.drop_console = flag;
      return args;
    });
    config.plugin('define').tap((definitions) => {
      Object.assign(definitions[0], {
        __VUE_OPTIONS_API__: 'true',
        __VUE_PROD_DEVTOOLS__: 'false',
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
      });
      return definitions;
    });
  },
  configureWebpack: {
    optimization: {
      splitChunks: {
        cacheGroups: {
          vendor: {
            test: /[\\/]node_modules[\\/]/,
            name: 'vendors',
            chunks: 'all',
          },
        },
      },
    },
    externals: {
      './remoteSync': 'commonjs2 ./remoteSync.js',
    },
    plugins: [
      require('unplugin-auto-import/webpack').default({
        resolvers: [require('unplugin-vue-components/resolvers').ElementPlusResolver()],
        eslintrc: {
          enabled: true,
          filepath: './.eslintrc-auto-import.json',
        },
        dts: false,
      }),
      require('unplugin-vue-components/webpack').default({
        resolvers: [require('unplugin-vue-components/resolvers').ElementPlusResolver()],
        dts: false,
      }),
    ],
  },
});
